﻿<UserControl x:Class="Apps.Yunwei.MapBrowser"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:Apps.Yunwei.ViewModels"
             xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:converts="clr-namespace:Apps.Yunwei.Converters"
             xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
    <UserControl.Resources>
        <sdk:HierarchicalDataTemplate x:Key="DataTemplate" ItemsSource="{Binding Children}">
            <StackPanel Orientation="Horizontal">
                <Border HorizontalAlignment="Left" VerticalAlignment="Center"
                        Background="{Binding Background}">
                    <Image Source="{Binding ImageUrl1}" Width="16" Height="16"/>
                </Border>
                <TextBlock Text="{Binding Caption}" Margin="2,2,0,2"/>
                <!--<TextBlock Text="{Binding Tags}" Margin="2,2,0,2"/>-->
            </StackPanel>
        </sdk:HierarchicalDataTemplate>
    </UserControl.Resources>
    <UserControl.DataContext>
        <local:MapBrowserViewModel/>
    </UserControl.DataContext>
    <Grid x:Name="LayoutRoot" Margin="5">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="250"/>
            <ColumnDefinition Width="5"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Border>
            <sdk:TreeView x:Name="treeView"
                          ItemsSource="{Binding Datas}"
                          ItemTemplate="{StaticResource DataTemplate}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="SelectedItemChanged" SourceName="treeView">
                        <i:InvokeCommandAction
                            Command="{Binding SelectedCommand}"
                            CommandParameter="{Binding SelectedItem, ElementName=treeView, Mode=OneWay}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </sdk:TreeView>
        </Border>
        <Border Grid.Column="2">
            <toolkit:ListBoxDragDropTarget
                AllowedSourceEffects="Copy"
                HorizontalContentAlignment="Stretch"
                VerticalContentAlignment="Stretch"
                ItemDragCompleted="ListBoxDragDropTarget_ItemDragCompleted"
                ItemDroppedOnTarget="ListBoxDragDropTarget_ItemDroppedOnTarget"
                AllowDrop="True" Drop="ListBoxDragDropTarget_Drop">
                <ListBox ItemsSource="{Binding Services}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid Width="80" Height="80" Margin="1">
                                <Border Background="{StaticResource TileBrush}"
                                        BorderThickness="1"
                                        BorderBrush="#ccc"/>
                                <Border Background="{Binding Bgc}" Margin="1"/>
                                <Image Source="{Binding Icon1}"
                                       Margin="16,5,16,27" Width="48" Height="48"/>
                                <TextBlock HorizontalAlignment="Center"
                                           VerticalAlignment="Bottom"
                                           Text="{Binding Caption}"
                                           TextWrapping="Wrap"
                                           Foreground="White" Margin="2"/>
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <toolkit:WrapPanel Width="550"/>
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                </ListBox>
            </toolkit:ListBoxDragDropTarget>
        </Border>
    </Grid>
</UserControl>
